/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package network;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import weibo4j.Friendships;
import weibo4j.Timeline;
import weibo4j.Weibo;
import weibo4j.model.Paging;
import weibo4j.model.Status;
import weibo4j.model.User;
import weibo4j.model.WeiboException;

/**
 *
 * @author Administrator
 */
public class test3 {

    public static void main(String[] args) throws WeiboException, FileNotFoundException, IOException, InterruptedException, ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException{
        prepareWeibo();
        DataPreparation data = new DataPreparation();
        List<Status> status = getStatus();
        printStatus(status, data);
    }

    public static void printStatus(List<Status> status, DataPreparation data) {
        for (Status s : status) {
            String un = s.getUser().getName();
            String source=s.getSource().getName();

            String tweetsource=null;
            if(s.getRetweetedStatus()!=null){
                tweetsource=s.getRetweetedStatus().getSource().getName();
            }
            String id = s.getUser().getId();
            if (data.data.agencyIDs.contains(id) || data.data.mediaIDs.contains(id) || data.data.zoombieIDs.contains(id)) {
                continue;
            }
            if (source.equals("皮皮时光机")||source.equals("定时V")||source.equals("定时showone")||source.equals("周博通微博管家")||source.equals("时光机")||source.equals("FaWave")||source.equals("定时达人")) {
                continue;
            }
            if(tweetsource!=null&&(tweetsource.equals("皮皮时光机")||tweetsource.equals("定时V")||tweetsource.equals("定时showone")||tweetsource.equals("周博通微博管家")||tweetsource.equals("时光机")||tweetsource.equals("FaWave")||tweetsource.equals("定时达人"))){
                continue;
            }
            
            System.out.println(un + " " + s.getText());
        }
    }

    public static List<Status> getStatus() throws WeiboException {
        List<Status> status = new ArrayList<Status>();
        String username = Config.username;
        String uid = Config.uid;
        Timeline tm = new Timeline();
        for (int i = 1; i < 5; i++) {
            System.out.println("Page " + i);
            List<Status> tmp = tm.getHomeTimeline(0, 0, new Paging(i, 200));
            if (!tmp.isEmpty()) {
                status.addAll(tmp);
            } else {
                break;
            }
        }
        return status;
    }

    public static void prepareWeibo() {
        String access = Auth.Auth4Code.getCode();
        Weibo weibo = new Weibo();
        weibo.setToken(access);
    }
}
